package cn.wolfcode.trip.app.util;

import freemarker.template.Configuration;
import freemarker.template.Template;

import java.io.File;
import java.io.Writer;

public abstract class FreemarkerUtil {
    private static Configuration cfg;

    static {
        cfg = new Configuration(Configuration.VERSION_2_3_28);
        cfg.setDefaultEncoding("UTF-8");
    }

    public static void wirteTempData(String dir, String tempName,
                                     Object model, Writer writer) throws Exception {
        cfg.setDirectoryForTemplateLoading(new File(dir));
        Template temp = cfg.getTemplate(tempName);
        temp.process(model, writer);
    }
}
